package com.zsxb.crm.controller;

import com.zsxb.crm.annotation.Log;
import com.zsxb.crm.dto.ActivityDto;
import com.zsxb.crm.dto.ActivityPageDto;
import com.zsxb.crm.pojo.Activity;
import com.zsxb.crm.result.PageResult;
import com.zsxb.crm.result.Result;
import com.zsxb.crm.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clues/activity")
@Slf4j
public class ActivityController {

    @Autowired
    private ActivityService activityService;
    //活动分页查询
    @GetMapping("/list")
    public PageResult pageQuery(ActivityPageDto dto){
        log.info("查询活动列表：{}",dto);
        PageResult pageResult = activityService.pageQuery(dto);
        return PageResult.success(pageResult);
    }
    //新增活动
    @PostMapping
    @Log
    public Result AddActivity(@RequestBody ActivityPageDto dto){
         log.info("新增活动：{}",dto);
         activityService.AddActivity(dto);
        return Result.success();
    }
    //删除活动
    @DeleteMapping("/{id}")
    @Log
    public Result delete(@PathVariable Long id){
        log.info("删除活动：{}",id);
        activityService.delete(id);
        return Result.success();
    }
    //修改活动
    @PutMapping
    @Log
     public Result update(@RequestBody ActivityDto dto){
         log.info("修改活动：{}",dto);
         activityService.update(dto);
         return Result.success();
     }
     //根据id查询活动
     @GetMapping("/{id}")
     public Result getById(@PathVariable Long id){
         log.info("根据id查询活动：{}",id);
       Activity activity =  activityService.getById(id);
         return Result.success(activity);
     }
    //根据id查询活动
    @GetMapping("/list/{id}")
    public Result getById2(@PathVariable Long id){
        log.info("根据id查询活动：{}",id);
        Activity activity =  activityService.getById(id);
        return Result.success(activity);
    }

    /**
     * 查询课程活动信息
     */
    @GetMapping("/listselect/{channel}")
    public Result<List<Activity>> getActivityByChannel(@PathVariable("channel") Integer channelId){
        return Result.success(activityService.getActivityByChannel(channelId));
    }

}
